package descentFly.sound
{
	import UIFree.FXContainer;
	
	import descentFly.server.df_servers;
	
	import flash.events.Event;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;

	public class df_sound extends Sound implements IDFSound {
		private var _fileName	: String;
		private var _channel	: SoundChannel;
		
		public function df_sound(a_fileName: String) {
			super(new URLRequest(df_servers.DATA_URL + a_fileName));
			_fileName = a_fileName;
		}
		
		public function get fileName(): String {
			return _fileName;
		}
		
		public function get loaded(): Boolean {
			return bytesLoaded == bytesTotal;
		}
		
		public function Play(startTime:Number=0, loops:int=0, a_volume: Number=0.5): void {
			if (_channel) _channel.stop();
			_channel = super.play(startTime, loops, new SoundTransform(a_volume));
		}
		
		public function get volume(): Number {
			return _channel.soundTransform.volume;
		}	
		
		public function set volume(a_volume: Number): void {
			if (_channel) _channel.soundTransform = new SoundTransform(a_volume);
		}	
		
		public function Stop(volumeEffect: Boolean=true): void {
			if (_channel) {
				if (volumeEffect) 
					(new FXContainer(this, 'volume', volume, 0, null, null, 10, 2000)).start(function(): void {
						_channel.stop();
						_channel = null;
					});
				else _channel.stop();
			}
		}
	}
}